<?php
namespace api\modules\v1\controllers;

use api\modules\v1\models\user\User;
use api\modules\v1\models\user\UserAttention;
use api\modules\v1\models\user\UserBusiness;
use api\modules\v1\models\user\UserGreet;
use api\modules\v1\models\user\UserKyc;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;
use Yii;

/**
 * Default controller for the `v1` module
 */
class UserController extends DefaultController
{

    public $modelClass = 'api\modules\v1\models\user\User';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }


    /**
     * 获取im签名
     * @return array
     */
    public function actionSig() {
        if (Yii::$app->request->isGet) {
            return (new User())->getSig();
        }
    }


    /**
     * 获取个人基本信息
     * @return array
     */
    public function actionInfo()
    {
        if (Yii::$app->request->isGet) {
            return (new User())->getInfo();
        }

        if (Yii::$app->request->isPost) {
            return (new User())->saveInfo();
        }
    }

    /**
     * 获取用户级别信息
     * @return array
     */
    public function actionLevelInfo()
    {
        if (Yii::$app->request->isGet) {
            return (new User())->getUserLevelInfo();
        }
    }


    /**
     * 获取用户列表
     * @return array
     */
    public function actionList()
    {
        if (Yii::$app->request->isPost) {
            return (new User())->getList();
        }
    }

    /**
     * 根据tx_code获取用户信息
     * @return array
     */
    public function actionTxInfo()
    {
        if (Yii::$app->request->isGet) {
            return (new User())->getTxInfo();
        }
    }


    //发送名片消息
    public function actionSendBusinessCard()
    {
        $model = new User();
        if (Yii::$app->request->isPost) {
            return $model->sendBusinessCard();
        }
    }

    //用户sky认证信息
    public function actionKyc()
    {
        $model = new UserKyc();
        if (Yii::$app->request->isGet) {
            return $model->getInfo();
        }
    }

    //用户关注   星标
    public function actionFollow() {
        if (Yii::$app->request->isPost) {
            return (new UserAttention())->getFollow();
        }

        if (Yii::$app->request->isDelete) {
            return (new UserAttention())->cancelFollow();
        }
    }

    //关注和粉丝列表   星标
    public function actionAttentionList() {
        if (Yii::$app->request->isGet) {
            return (new UserAttention())->getAttentionList();
        }
    }

    //推荐列表
    public function actionInterestList() {
        if (Yii::$app->request->isGet) {
            return (new UserAttention())->getInterestList();
        }
    }


    //用户注销
    public function actionCancellation() {
        if (Yii::$app->request->isDelete) {
            return (new User())->cancellation();
        }
    }


    /* ======================  打招呼 ========================= */
    /**
     * 获取需要打招呼的人
     * @return array
     */
    public function actionGreet()
    {
        if (Yii::$app->request->isGet) {
            return (new UserGreet())->getNeedUserList();
        }

        if (Yii::$app->request->isPost) {
            return (new UserGreet())->greet();
        }
    }

    /**
     * 收到的招呼
     * @return array
     */
    public function actionReceiveGreet()
    {
        if (Yii::$app->request->isGet) {
            return (new UserGreet())->getReceiveList();
        }
    }

    /**
     * 是否能打招呼
     * @return array
     */
    public function actionCanGreet()
    {
        if (Yii::$app->request->isPost) {
            return (new UserGreet())->canGreet();
        }
    }


    /* ======================  附近的人 ========================= */
    /**
     * 查找附近的人
     * @return array
     */
    public function actionNearby()
    {
        if (Yii::$app->request->isGet) {
            return (new User())->getNearby();
        }
    }

    /**
     * 谁看过我
     * @return array
     */
    public function actionViewList()
    {
        if (Yii::$app->request->isGet) {
            return (new User())->getViewList();
        }
    }

    /**
     * 商户信息
     * @return array
     */
    public function actionBusiness()
    {
        $model = new UserBusiness();
        if (\Yii::$app->request->isPost) {
            $model->setScenario('addEdit');
            if ($model->load(\Yii::$app->request->post(), '')) {
                return $model->saveBusiness();
            }
        }

        if (Yii::$app->request->isGet) {
            return $model->getInfo();
        }
    }

}
